package com.tangmimi.friends.once;

import com.alibaba.excel.EasyExcel;

import java.util.List;

/**
 * 读取数据
 */
public class ImportExcel {
    public static void main(String[] args) {

        // 写法1：JDK8+ ,不用额外写一个DemoDataListener
        // since: 3.0.0-beta1
        String fileName = "F:\\webproject\\user-center\\src\\main\\resources\\testdemo.xlsx";
        //readByListener(fileName);
        synchronousRead(fileName);
    }

    /**
     * 监听器读 方法一
     * @param fileName
     */
    private static void readByListener(String fileName) {
        EasyExcel.read(fileName, XingQiuUserInfo.class, new TableListener()).sheet().doRead();
    }

    /**
     * 同步读 方法二
     * @param fileName
     */
    public static void synchronousRead(String fileName) {
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 同步读取会自动finish
        List<XingQiuUserInfo> totalDataList = EasyExcel.read(fileName).head(XingQiuUserInfo.class).sheet().doReadSync();
        for (XingQiuUserInfo xingQiuUserInfo: totalDataList){
            System.out.println(xingQiuUserInfo);
        }
    }

}
